package com.dragon.logical.service.protoBuilder;

import cn.hutool.json.JSONUtil;
import com.dragon.protoJo.bean.msg.ProtoMsg;
import com.dragon.repository.entity.DoReminder;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.UUID;

public class ProtoMessageBuilder {

    /**
     *  构建发送消息proto
     * @return
     */
    public static ProtoMsg.Message buildNotifyMessage(DoReminder doReminder){
        ProtoMsg.Message.Builder mb = ProtoMsg.Message.newBuilder()
                .setType(ProtoMsg.HeadType.MESSAGE_NOTIFICATION)  //设置消息类型
                .setSessionId(UUID.randomUUID().toString().replace("-","")); // 设置消息sessionId
        ProtoMsg.MessageNotification.Builder builder = ProtoMsg.MessageNotification.newBuilder()
                .setNoId(doReminder.getAdminId())
                .setTimestamp(String.valueOf(Math.toIntExact(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")))))
                .setJson(JSONUtil.toJsonStr(doReminder));
        mb.setNotification(builder.build());
        return mb.build();
    }


}
